home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '93 / Papers '93 / Macintosh as Internet Server ƒ / inetd / Libraries / DaemonApp / CList.cp next >
Encoding:
Text File  |  1993-04-07  |  1.5 KB  |  77 lines  |  [TEXT/MPS ]

  1. //---------------------------------------------------------------------
  2. //
  3. //    Copyright © 1992 David Peterson.
  4. //    All rights reserved.
  5. //
  6. //    Permission to use, copy, modify, and distribute this software for
  7. //    any purpose and without fee is hereby granted, provided that the
  8. //    above copyright notice appear in all copies and that both that
  9. //    copyright notice and this permission notice appear in supporting
  10. //    documentation.
  11. //
  12. //---------------------------------------------------------------------
  13.  
  14. #include "CList.h"
  15.  
  16. CList::~CList()
  17. {
  18.     CItem*    it;
  19.     
  20.     while (it = this->First()) {
  21.         this->TakeOff(it);
  22.         delete it;
  23.     }
  24. }
  25.  
  26. CItem*
  27. CList::PutOn(CItem* nu)
  28. {
  29.     nu->fNext = 0;        // we're going on the end. period.
  30.  
  31.     if (fTail)             // there is something else here…
  32.         fTail->fNext = nu;
  33.     else                 // we're the only one, head points to us
  34.         fHead = nu;
  35.     
  36.     fTail = nu;
  37.     
  38.     return nu;
  39. }
  40.  
  41. CItem*
  42. CList::TakeOff(CItem* off)
  43. {
  44.     CItem*    prev = 0;
  45.     
  46.     if (off == fHead) {                // are we at the head?
  47.         fHead = off->fNext;
  48.     }
  49.     else {
  50.         prev = fHead;                // prev is element before us
  51.         while (prev->fNext && (prev->fNext != off))
  52.             prev = prev->fNext;
  53.             
  54.         if (prev->fNext == off)        // were we even found?
  55.             prev->fNext = off->fNext;
  56.     }
  57.     
  58.     if (off == fTail)                // did we also happen to be at the tail?
  59.         fTail = prev;
  60.  
  61.     return off;
  62. }
  63.  
  64. CItem*
  65. CList::IsOn(CItem* test)
  66. {
  67.     CItem*    it = fHead;
  68.  
  69.     // while there are more elements and they aren't us move forward
  70.     while (it && (it != test))
  71.         it = it->fNext;
  72.     
  73.     // return us or null
  74.     return it;
  75. }
  76.  
  77.